<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工资管理</title>
    <#include "/common/link.ftl">

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">
    <#include "/common/navbar.ftl">

    <#assign currentMenu="salary"/>

    <#include "/common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>工资管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <form class="form-inline" id="searchForm" action="/salary/list" method="post">
                    <input type="hidden" name="currentPage" id="currentPage" value="1">
                    <div class="form-group">
                        <label for="keyword">关键字:</label>
                        <input type="text" class="form-control" name="keyword" placeholder="请输入姓名" value="${qo.keyword}">
                    </div>
                    <div class="form-group">
                        <label> 发放方式:</label>
                        <select class="form-control" name="payoutId" id="payoutId" data-Id="${qo.payoutId}">
                            <option value="">全部</option>
                        </select>

                    </div>
                    <div class="form-group">
                        <label>工资范围查询：</label>
                        <input placeholder="请输入最低工资" type="text" class="form-control " name="minSalary" value="${qo.minSalary}"/> -
                        <input placeholder="请输入最高工资" type="text" class="form-control " name="maxSalary" value="${qo.maxSalary}"/>
                    </div>
                    <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span> 查询
                    </button>
                    <a href="#" class="btn btn-success btn-input" style="margin: 10px">
                        <span class="glyphicon glyphicon-plus"></span> 添加
                    </a>
                </form>
                <!--编写内容-->
                <div class="box-body table-responsive">
                    <table class="table table-hover table-bordered table-striped">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>年份</th>
                            <th>月份</th>
                            <th>员工</th>
                            <th>工资</th>
                            <th>发放方式</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <#list  pageInfo.list as s>
                            <tr>
                                <td>${s_index+1}</td>
                                <td>${s.year}</td>
                                <td>${s.month}</td>
                                <td>${s.employee.name}</td>
                                <td>${s.money}</td>
                                <td>${s.payout.title}</td>
                                <td>
                                    <a href="#" class="btn btn-info btn-xs btn-input" data-json='${s.toJson()}'>
                                        <span class="glyphicon glyphicon-pencil"></span> 编辑
                                    </a>
                                </td>
                            </tr>
                        </#list>
                        </tbody>
                    </table>
                    <#include "/common/page.ftl" >
                </div>
            </div>
        </section>
    </div>
    <#include "/common/footer.ftl" >
</div>
<!-- Modal -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <form class="form-horizontal" action="/salary/saveOrUpdate" method="post" id="editForm">
                <div class="modal-body">
                    <input type="hidden" name="id" value="id">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">年份：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="year"
                                   placeholder="请输入年份">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">月份：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="month"
                                   placeholder="请输入月份">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">员工：</label>
                        <div class="col-sm-6">
                            <select type="text" class="form-control" name="employee.id" id="emp">
                                <option value="">请选择员工</option>
                                <#list employees as e>
                                <option value="${e.id}">${e.name}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">工资：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="money"
                                   placeholder="请输入工资">
                        </div>
                    </div>
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">发放方式：</label>
                        <div class="col-sm-6">
                            <select type="text" class="form-control" name="payout.id">

                            </select>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-primary btn-submit">保存</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script>
        //给新增或者编辑绑定一个点击事件(类选择器)
        $(".btn-input").click(function () {
            //清除表单中的数据
            $("#editForm input").val('');
            $("#editForm select").val('');
            //从按钮中能获取数据
            let json = $(this).data("json");
            if (json){
                //通过DOM操作回显
                $("input[name=id]").val(json.id);
                $("input[name=year]").val(json.year);
                $("input[name=month]").val(json.month);
                $("input[name=money]").val(json.money);
                $("select[name='employee.id']").val(json.employee.id);
                $("select[name='payout.id']").val(json.payout.id);
            }
            //弹出模态框
            $('#editModal').modal('show')
        });


//共用一个AJAX
$(function () {
    $("select[name=payoutId]").val("");
    $.get('/systemDictionaryItem/selectByTypeSn',{sn:'pay_type'},function (data) {
        let str = '<option value="">请选择支付方式</option>';
        $.each(data,function (index,ele) {
            str += '<option value="'+ele.id+'">'+ele.title+'</option>'
        });
        //用于显示模态框的下拉框回显
        $("select[name='payout.id']").html(str);
        //用于显示高查中的的下拉框数据
        $("select[name=payoutId]").html(str);
        //用于下拉框数据回显
        $("select[name=payoutId]").val(${qo.payoutId})
    });
})


</script>
</body>
</html>
